﻿using System.Linq;
using System.Web.Mvc;
using ASPItalia.ModelVirtualCasting.Web.Filters;
using ASPItalia.ModelVirtualCasting.Web.Models;
using ASPItalia.ModelVirtualCasting.Common;
using System;

namespace ASPItalia.ModelVirtualCasting.Web.Controllers
{
    [HandleError]
    public class NewsController : Controller
    {
        #region refactoring per testability
        private INewsRepository newsRepository;
        
        internal NewsController(INewsRepository newsRepository)
        {
            if (newsRepository == null)
                throw new ArgumentNullException("newsRepository");

            this.newsRepository = newsRepository;
        }

		public NewsController()
            : this(ApplicationContext.Current.News)
        { }
        #endregion

        #region Index
        [ShowNews(Number = 30)]
		public ActionResult Index()
        {
            this.ViewData.Model = new NewsViewModel();
            return View();
        }
        #endregion

		#region Details
		public ActionResult Details(int id)
		{
			this.ViewData.Model = new NewsDetailsViewModel
			{
				NewsDetail = this.newsRepository.GetByID(id)
			};

			return View();
		}
		#endregion
	}
}